package com.xjaq.dify.http;

import cn.hutool.http.HttpResponse;
import com.github.lianjiatech.retrofit.spring.boot.annotation.Intercept;
import com.github.lianjiatech.retrofit.spring.boot.annotation.RetrofitClient;
import com.xjaq.dify.common.Result;
import com.xjaq.dify.entity.AnnotationReplyRequest;
import com.xjaq.dify.entity.ConversationRenameRequest;
import com.xjaq.dify.entity.CreateAnnotationRequest;
import com.xjaq.dify.entity.DeleteConversationRequest;
import com.xjaq.dify.entity.DifyRequest;
import com.xjaq.dify.entity.FeedbackRequest;
import com.xjaq.dify.entity.UpdateAnnotationRequest;
import com.xjaq.dify.interceptor.DifyInterceptor;
import io.swagger.annotations.ApiModelProperty;
import okhttp3.ResponseBody;
import org.springframework.stereotype.Component;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.http.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@Intercept(handler = DifyInterceptor.class)
@RetrofitClient(baseUrl = "${dify.base-url}",readTimeoutMs = 30000, connectTimeoutMs = 100000, writeTimeoutMs = 100000)
public interface HttpApi {
    // 聊天
    @Streaming
    @POST("chat-messages")
    Call<ResponseBody> chatMessages(@Body DifyRequest difyRequest);
    // 停止聊天
    @POST("chat-messages/{task_id}/stop")
    Call<ResponseBody> stopChatTask(@Path("task_id") String taskId, @Body Map<String, String> requestBody);
    // 消息反馈
    @POST("messages/{message_id}/feedbacks")
    Call<ResponseBody> messageFeedback(
            @Path("message_id") String messageId,
            @Body FeedbackRequest feedbackRequest);
    // 获取应用反馈
    @GET("app/feedbacks")
    Call<ResponseBody> getAppFeedbacks(@QueryMap Map<String, Object> params);
    // 获取建议问题
    @GET("messages/{message_id}/suggested")
    Call<ResponseBody> getSuggestedQuestions(
            @Path("message_id") String messageId,
            @Query("user") String user
    );

    // 获取消息历史
    @GET("messages")
    Call<ResponseBody> getMessageHistory(@QueryMap Map<String, Object> params);

    // 获取会话列表
    @GET("conversations")
    Call<ResponseBody> getConversations(@QueryMap Map<String, Object> params);
    // 删除会话
    @HTTP(method = "DELETE", path = "conversations/{conversation_id}" , hasBody = true)
    Call<ResponseBody> deleteConversation(@Path("conversation_id") String conversationId, @Body DeleteConversationRequest request);
    @POST("conversations/{conversation_id}/name")
    Call<ResponseBody> renameConversation(@Path("conversation_id") String conversationId, @Body ConversationRenameRequest request);
    @GET("conversations/{conversation_id}/variables")
    Call<ResponseBody> getConversationVariables(@Path("conversation_id") String conversationId, @QueryMap Map<String, Object> params);
    @GET("info")
    Call<ResponseBody> getAppInfo();
    @GET("meta")
    Call<ResponseBody> getAppMeta();
    @GET("site")
    Call<ResponseBody> getWebAppSettings();
    @GET("apps/annotations")
    Call<ResponseBody> getAnnotations(@QueryMap Map<String, Object> params);
    @POST("apps/annotations")
    Call<ResponseBody> createAnnotation(@Body CreateAnnotationRequest request);
    @PUT("apps/annotations/{annotation_id}")
    Call<ResponseBody> updateAnnotation(@Path("annotation_id") String annotationId, @Body UpdateAnnotationRequest request);
    @DELETE("apps/annotations/{annotation_id}")
    Call<ResponseBody> deleteAnnotation(@Path("annotation_id") String annotationId);
    @POST("apps/annotation-reply/{action}")
    Call<ResponseBody> annotationReply(@Path("action") String action, @Body AnnotationReplyRequest request);
    @GET("apps/annotation-reply/{action}/status/{job_id}")
    Call<ResponseBody> getAnnotationReplyStatus(@Path("action") String action, @Path("job_id") String jobId);

}
